<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>外边距</title>
  <style>
    #d1{
      width: 100px;
      height: 100px;
      background-color: red;
      /*设置外边剧*/
      margin: 0 auto;
      /*解决子元素溢出问题*/
      overflow: auto;
    }

    #d2{
      width: 50px;
      height: 50px;
      background-color: chartreuse;

      margin-left: 70px;
    }
  </style>
</head>
<body>
  <div id="d1">div1
    <div id="d2">div2</div>
  </div>

</body>
</html>